import { ref } from 'vue';
import  axios  from 'axios';

interface HttpResponse {
    loading:boolean,loaded:boolean,result:any;error:any
}

function useHttpRequest(url:string){
    const ret:HttpResponse = {'loading':true,'loaded':false,result:null,error:null};
    
    axios.get(url).then((res:any) => {
        ret.loading = false;
        ret.loaded = true;
        ret.result = res.data;
        ret.error = null;
    }).catch((e:any)=>{
        ret.loading = true;
        ret.loaded = false;
        ret.result = null;
        ret.error = e;
    })

    return ref(ret);
    
}

export default useHttpRequest